package tests;

import org.junit.*;

import parser.ParserException;

/**
 * Test class that tests the basic functions of the parser Test is using JUnit 4
 * 
 * @author sebastian
 * 
 */

public class ParserTest {

	/**
	 * Tests left associative expressions
	 * 
	 * @throws ParserException
	 */
	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void testLeftAssociativeExpression() throws Exception {
		TestUtil.testParserExpression("x+y+z", "+(+(x, y), z)");
		TestUtil.testParserExpression("x*y*z", "*(*(x, y), z)");
	}

	/**
	 * Testing a minimal program. You have to change the filename in import to
	 * your favorite filename. To test, remove @-Ignore-expression. Please do
	 * not upload without @-Ignore
	 * 
	 * @throws ParserException
	 */
	@Ignore
	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void testMinimalProgram() throws ParserException {
		TestUtil.testParser("MainClass : A.f.G.f ; "
				+ " import /home/sebastian/test.txt as TEST ;", "A.f.G.f( )");
	}

	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void fieldAndArrayAccess() throws ParserException {
		TestUtil.testParser("MainClass : none; class Test { }", "none( )");
	}

	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void syntacticSugarTest() throws ParserException {
		TestUtil
				.testParser(
						"MainClass : none; class Xmas { int i = 8; } "
								+ "class Test { int test(boolean d) "
								+ "{ Xmas[] test = new Xmas[8]; test[7].i = test[7].i++; return 0; } }",
						"none( )");
	}

	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void modifiersTest() throws ParserException {
		TestUtil.testParser(
				"MainClass: none; class Test { public int x = 9; }", "none( )");
	}

	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void staticMethodTest() throws ParserException {
		TestUtil
				.testParser(
						"MainClass: none; class Test { construct(int i) { }"
								+ "public int x = 9; static boolean method() {return true;} }",
						"none( )");
	}

	@Test(timeout = TestUtil.DEFAULT_TIMEOUT)
	public void constructorTest() throws ParserException {
		TestUtil.testParser(
				"MainClass: none; class Test { construct(int x, int y) { } }",
				"none( )");
	}

}
